package com.fuhaiwei.struts.action.impl;

import com.fuhaiwei.basic.utils.TextUtils;
import com.fuhaiwei.domain.service.RegisterResult;
import com.fuhaiwei.struts.action.RegisterAction;

public class RegisterActionImpl extends RegisterAction {

	public String execute() throws Exception {
		RegisterResult result = getRegisterService().doRegister(getUsername(),
				getPassword());
		if (result == RegisterResult.REGISTER_SUCCESS) {
			getSession().put(SESSION_USER_NAME, getUsername());
			return SUCCESS;
		}
		if (result == RegisterResult.USERNAME_EXISTS) {
			setTip(getTextUtils().text(TextUtils.INPUT_EXISTS,
					getTextUtils().label(USERNAME)));
			return INPUT;
		}
		if (result == RegisterResult.DATABASE_ERROR) {
			setTip(getTextUtils().text(TextUtils.ERROR_DATABASE));
			return INPUT;
		}
		setTip(getTextUtils().text(TextUtils.ERROR_RETURN));
		return INPUT;
	}

}
